From: Jan Beulich Date: Wed, 7 Sep 2011 09:36:55 +0000 (+0100) Subject: bitmap_scnlistprintf() should always zero-terminate its output buffer X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~9916 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=cd4ab341d27ee080ccad1cf85a366606a98dbc49;p=xen.git bitmap_scnlistprintf() should always zero-terminate its output buffer ... as long as it has non-zero size. So far this would not happen if the passed in CPU mask was empty. Also fix the comment describing the return value to actually match reality. Signed-off-by: Jan Beulich --- diff --git a/xen/common/bitmap.c b/xen/common/bitmap.c index 363572bedb..a34f519359 100644 --- a/xen/common/bitmap.c +++ b/xen/common/bitmap.c @@ -363,9 +363,8 @@ static inline int bscnl_emit(char *buf, int buflen, int rbot, int rtop, int len) * the range. Output format is compatible with the format * accepted as input by bitmap_parselist(). * - * The return value is the number of characters which would be - * generated for the given input, excluding the trailing '\0', as - * per ISO C99. + * The return value is the number of characters which were output, + * excluding the trailing '\0'. */ int bitmap_scnlistprintf(char *buf, unsigned int buflen, const unsigned long *maskp, int nmaskbits) @@ -383,6 +382,8 @@ int bitmap_scnlistprintf(char *buf, unsigned int buflen, rbot = cur; } } + if (!len && buflen) + *buf = 0; return len; } EXPORT_SYMBOL(bitmap_scnlistprintf);